﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core;
using Telerik.Windows.Controls.GridView;
using Baosight.ZNH.ZM.UI.PopWindows;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Telerik.Windows.Controls;
using Baosight.Platform.Core.ServiceModel;
using Baosight.Platform.Core.UI.Controls;

namespace Baosight.ZNH.ZM.UI
{
    /// <summary>
    /// 首页配置管理-选择模块
    /// </summary>
    /// Title:ZM9Q，ServiceZM9Q
    /// Copyright:Baosight Software LTD.co Copyright (c) 2011
    /// Company:上海宝信软件股份有限公司
    /// Author: 高强
    /// Version: 1.0
    /// History:
    ///       2012-12-06  高强   [创建]
    ///
    public partial class ZM9Q : EFViewCmes
    {
        public ZM9Q()
        {
            InitializeComponent();
            this.BeforeAction += OnBeforeAction;
        }

        public override void Initialize(EIInfo initData)
        {
            base.Initialize(initData);

        }

        /// <summary>
        /// 修改前设置属性
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.EFGridCheckedRows = this.grid.GetCheckedEIRows();
            base.ViewProperty = _view;
        }

        /// <summary>
        /// 绑定值到指定的Block内 
        /// </summary>
        /// <param name="block"></param>
        /// <param name="columnName"></param>
        /// <param name="dataValue"></param>
        private void BindToBlock(EIBlock block, string columnName, object dataValue, EIRow row)
        {
            EIColumn column = new EIColumn();
            column.SetName(columnName);
            row.Add(columnName, dataValue);
            block.AddColumn(column);
        }

        /// <summary>
        /// “选择模块”按钮执行事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnSELECTMODULEButtonClick(object sender, RoutedEventArgs e)
        {
            Button but = sender as Button;
            but.IsEnabled = false;
            TempButton = but;

            EIInfo eiInfo = new EIInfo();
            HttpServiceAgent agent = new HttpServiceAgent();
            eiInfo.Attributes.Add(EIConstants.ServiceNameKey, "ZM9Q");
            eiInfo.Attributes.Add(EIConstants.MethodNameKey, "queryModule");
            agent.CallService(eiInfo, OnDoSelectCompleted);
        }

        /// <summary>
        /// 选择隐患的回调函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnDoSelectCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status == -1)
            {
                base.OpenEFWindowAlert(e.EIInfo.GetMsg(), true);
                return;
            }

            if (e.EIInfo.GetBlock("moduleResult").GetRowCount() == 0)
            {
                base.OpenEFWindowAlert("已经选中了全部的模块！", true);
                return;
            }

            SelectModule SelectModule = new SelectModule();
            CmesWindows _popup = new CmesWindows();//构造一个弹出页面
            _popup.Header = "选择模块记录";
            _popup.ResizeMode = ResizeMode.NoResize;
            _popup.WindowStartupLocation = Telerik.Windows.Controls.WindowStartupLocation.CenterScreen;
            SelectModule.EIDataContext = new Platform.Core.UI.EIDataContext();
            SelectModule.EIDataContext.Update(e.EIInfo);
            SelectModule.fdDepartmentId.Value = this.fdDepartmentId.Value;
            _popup.Content = SelectModule;
            _popup.Closed += new EventHandler<WindowClosedEventArgs>(Window_Closed);
            _popup.ShowDialog();
            _popup.DialogResult = false;
        }

        /// <summary>
        /// 弹出窗口关闭时执行的方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Closed(object sender, WindowClosedEventArgs e)
        {
            if (e.DialogResult == true)
            {
                //刷新Grid区域
                this.grid.Refresh();
            }
            //按钮生效
            base.TempButtonOpen(true);
            //超链接生效
            if (base.TempHyperlink != null)
            {
                base.TempHyperlink.IsEnabled = true;
                base.TempHyperlink = null;
            }
        }
    }
}
